// 封装了关于用户相关请求,登录,获取个人信息,修改个人信息....
// 导入axios实例
import http from '@/utils/request'
// 导入store
// import store from '@/store'
// 用户登录api
export const reqLogin = (mobile, code) => {
  return http({
    method: 'POST',
    url: 'v1_0/authorizations',
    data: {
      mobile,
      code
    }
  })
}
// 获取个人信息
export const reqGetProfile = () => {
  // const token = store.state.user.tokenInfo.token
  return http({
    method: 'GET',
    url: 'v1_0/user/profile'
    // 手动配置了headers 添加token
    // 访问vuex中存储的token
    // headers: {
    //   Authorization: 'Bearer ' + token
    // }
  })
}
// 获取关注列表
export const reqGetFollowings = () => {
  // const token = store.state.user.tokenInfo.token
  return http({
    method: 'GET',
    url: 'v1_0/user/followings'
    // headers: {
    //   Authorization: 'Bearer ' + token
    // }
  })
}
// 关注用户的api
export const reqFollowUser = (target) => {
  return http({
    method: 'POST',
    url: '/v1_0/user/followings',
    data: {
      target // 关注的用户id
    }
  })
}
// 取关用户api
export const reqUnFollowUser = (target) => {
  return http({
    method: 'DELETE',
    url: 'v1_0/user/followings/' + target // 取关的用户id
  })
}

// 刷新用户token接口
export const reqGetNewToken = (refresh_token) => {
  return http({
    method: 'PUT',
    url: 'v1_0/authorizations',
    // 设置请求头携带refresh_token
    headers: {
      Authorization: 'Bearer ' + refresh_token
    }
  })
}
// 获取用户自己信息资料
export const reqGetUserInfo = () => {
  return http({
    method: 'get',
    url: '/v1_0/user'
  })
}

// 编辑用户资料  get/delete params  post/put/pacth data
export const reqEditUserProfile = (obj) => {
  return http({
    method: 'PATCH',
    url: 'v1_0/user/profile',
    // params  data
    data: obj // obj就是更改的用户数据,可以是一项,也可以是多项
  })
}

// 更改头像
export const reqEditUserPhoto = (fm) => {
  return http({
    method: 'PATCH',
    url: 'v1_0/user/photo',
    data: fm
  })
}
